﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

/// <summary>
/// SystemTools 的摘要说明
/// </summary>
public class SystemTools
{
	public SystemTools()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public static DataTable ConvertDataToDataTable(OleDbDataReader dataReader)
    { DataTable datatable = new DataTable();
        try
        {
            for (int i = 0; i < dataReader.FieldCount; i++)
            {
                DataColumn MyColumn = new DataColumn();
                MyColumn.DataType = dataReader.GetFieldType(i);
                MyColumn.ColumnName = dataReader.GetName(i);
                datatable.Columns.Add(MyColumn);
            }

            while (dataReader.Read())
            {
                DataRow dr = datatable.NewRow();
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    dr[i] = dataReader[i].ToString();
                }
                datatable.Rows.Add(dr);
            }
            dataReader.Close();
            return datatable;
        }
        catch (Exception ex)
        { throw new Exception(ex.Message,ex); }
    }

    public static void PopMsg(string msg)
    {
        string jsmsg = "<script language=javascript>";
        jsmsg += "window.alert('";
        jsmsg += msg;
        jsmsg += "');";
        jsmsg += "</script>";

        HttpContext.Current.Response.Write(jsmsg);
    }

    public static void PopMsg(string msg,string redir)
    {
        string jsmsg = "<script language=javascript>";
        jsmsg += "window.alert('";
        jsmsg += msg;
        jsmsg += "');";
        jsmsg += "window.location='";
        jsmsg += redir;
        jsmsg += "';";
        jsmsg += "</script>";

        HttpContext.Current.Response.Write(jsmsg);
    }

    public static string CreateFileNameByDataTime()
    { DateTime now = DateTime.Now;
    string filename = now.Year.ToString()
                            + now.Month.ToString()
                            + now.Day.ToString()
                            + now.Hour.ToString()
                            + now.Minute.ToString()
                            + now.Second.ToString()
                            + now.Millisecond.ToString();
    return filename;
    }
}
